from fileinput import filename
import os
import logging
import datetime

def initLog(*, dir="./log/tmp", level="INFO", phase="train"):
    cur_path = __file__
    now = datetime.datetime.now()

    path = os.path.dirname(cur_path)
    path = os.path.dirname(path)

    filename = now.strftime("%Y-%m-%d-&-%H-%M-%S.log")
    filename = phase + filename
    path = os.path.normpath(
        os.path.join(path, dir, filename)
    )

    if type(level) == str:
        if level == "NOTSET":
            level = logging.NOTSET
        elif level == "DEBUG":
            level = logging.DEBUG
        elif level == "INFO":
            level = logging.INFO
        elif level == "WARNING":
            level = logging.WARNING
        elif level == "ERROR":
            level = logging.ERROR
        elif level == "CRITICAL":
            level = logging.CRITICAL

    logging.basicConfig(filename=path, level=level)




if __name__ == "__main__":
    initLog()
    logger = logging.getLogger("this")
    logger.info("1y2t37887gvbsdvbhafhjd")
    logger.info("123hgdsvfahjvs")
    logger.info("qw3rdsacxz")
    logger.info("123refsdadvc")
    logger.info("asdfsdadfsav")
    logger.info("werewfafds")